/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package rentcalculator.persist;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author K.E.Y
 */
public class SessionController {
    
    private static final Configuration cfg = new Configuration();
    private static SessionFactory sf = null;
    private static SessionController sc = null;
    private SessionController(){
        cfg.configure("resources/hibernate.cfg.xml");
        sf = cfg.buildSessionFactory(new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build());
    }
    
    public static SessionController getInstance(){
        if (sc == null ){
            sc = new SessionController();
        }
        return sc;
    }
    
    public Session getSession(){
        return SessionController.sf.openSession();
    }
    
    public void close(){
        SessionController.sf.close();
    }
     
            
            
}
